package _021_10_5

type ListNode struct {
	Val  int
	Next *ListNode
}

func FindFirstCommonNode(pHead1 *ListNode, pHead2 *ListNode) *ListNode {
	// write code here
	_pHead1 := pHead1
	_pHead2 := pHead2
	if pHead1 == nil || pHead2 == nil {
		return nil
	}
	for _pHead1 != nil || _pHead2 != nil {
		if _pHead1 == _pHead2 {
			return _pHead1
		}
		if _pHead1 == nil {
			return nil
		}
		if _pHead2 == nil {
			return nil
		}
		_pHead1 = _pHead1.Next
		_pHead2 = _pHead2.Next
	}
	return nil
}
